export default function (func, waitTime, immediate = true) {
	let timer = null
	let flag = !immediate
	return function () {
		if (immediate) {
			func.apply(this, arguments)
			immediate = false
		}
		if (timer) clearTimeout(timer)
		timer = setTimeout(function () {
			if (flag) {
				func.apply(this, arguments)
			} else {
				immediate = true
			}
		}, waitTime)
	}
}